package hit.core;

import static org.junit.Assert.*;

import org.junit.Test;

public class BarcodeTest {
	
	@Test
	public void TestValidCreation() {
		
		Barcode testCode1 = new Barcode("036000291452");
		assertTrue("Valid Barcode 036000291452 failed", Barcode.IsValid(testCode1));
		
		Barcode testCode2 = new Barcode("885370395143");
		assertTrue("Valid Barcode 885370395143 failed", Barcode.IsValid(testCode2));
		
		Barcode testCode3 = new Barcode("036725604919");
		assertTrue("Valid Barcode 036725604919 failed", Barcode.IsValid(testCode3));
		
		Barcode testCode4 = new Barcode("400000123455");
		assertTrue("Valid Barcode 400000123455 failed", Barcode.IsValid(testCode4));
	}
	
	@Test
	public void TestIsLocal() {
		Barcode localCode = new Barcode("400000123455");
		assertTrue("Local Code not returning Local.", localCode.IsLocal());
		
		Barcode nonlocalCode = new Barcode("036725604919");
		assertFalse("Non-local code returned Local.", nonlocalCode.IsLocal());
	}
	
	@Test
	public void TestSetAndGet() {
		Barcode testCode = new Barcode("036000291452");
		assertEquals("Did not return expected value.", "036000291452", testCode.GetValue());
		
		testCode.SetValue("885370395143");
		assertEquals("Did not return expected value.", "885370395143", testCode.GetValue());
		
		testCode.SetValue("400000123455");
		assertEquals("Did not return expected value.", "400000123455", testCode.GetValue());
	}
	
	
	@Test
	public void TestGetNewLocalCode()
	{
		Barcode test = Barcode.GetLocalBarcode(1);
		assertEquals("ID: 1 did not return expected Barcode value.", "400000000015", test.GetValue());
		
		test = Barcode.GetLocalBarcode(12345);
		assertEquals("ID: 12345 did not return expected Barcode value.", "400000123455", test.GetValue());
		
		test = Barcode.GetLocalBarcode(28402124);
		assertEquals("ID: 28402124 did not return expected Barcode value.", "400284021249", test.GetValue());
	}
}
